package com.baizhi.dcx.service;

import com.baizhi.dcx.dao.UserDao;
import com.baizhi.dcx.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class UserServiceImpl implements UserService{
    @Autowired
    private UserDao userDao;
    @Override
    public Map<String, Object> queryAllPage(int page, int pageSize) {
        Map<String,Object> map = new HashMap<String,Object>();
        List<User> list = userDao.SelectPage(page, pageSize);
        int i = userDao.selectTotalCount();
        map.put("total", i);
        map.put("page", page);
        map.put("rows", list);
        return map;
    }

    @Override
    public Map<String, Object> mifig(User user) {
        Map<String, Object> map = new HashMap<String,Object>();
        try {
            map= userDao.Update(user);
            map.put("massage","修改成功");
            map.put("status",200);
            return map;
        }catch (Exception e){
            map.put("massage","修改失败");
            map.put("status",400);
            return map;

        }
    }

    @Override
    public User queryById(int id) {
        return userDao.selectById(id);
    }
}
